<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
global $config;

require_once ($config['base_dir'] . "/../lib/db.php");

class zhangguiDBTool {

    var $db;

    function __construct() {
        $this->ensureDB();
    }

    function getAllMealCount() 
    {    
        $sql = "select count(*) count from meal";
        $data = $this->db->__query($sql, "Q");
        
        //*
        while($data->next())
        {
            $count = $data->count;
        }
        //*/
        
        return $count;
    }

    function getMeals($index, $count) {
        $sql = "select * from meal limit {$index} , {$count}";

        $data = $this->db->__query($sql, "Q");

        /*
        while ($data->next()) {
            print_r($data->__data);
        }
        */
        return $data;
    }

    private function ensureDB() {
        global $zhangguiInfo, $config;
        require_once($config['base_dir'] . "/core/baseInfo.php");

        try {
            if (empty($this->db))
                $this->db = new DB($zhangguiInfo['db']['host']
                                , $zhangguiInfo['db']['dbname']
                                , $zhangguiInfo['db']['user']
                                , $zhangguiInfo['db']['pass']);
        } catch (Expection $e) {
            print_r($e);
            exit();
        }
    }

}

?>
